package com.esd.controller.csair;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.esd.csair.CS;
import com.esd.csair.Csair;
import com.esd.csair.CsairImpl;
import com.esd.csair.CsairReturnValue;

/**
 * 
 * 支付模块
 * 
 * @author snailzhang
 * @date 2017年7月20日
 *
 */
@Controller
@RequestMapping(value = "cs")
public class CsELoginController {

	private static Logger log = Logger.getLogger(CsELoginController.class);
	/**
	 * 动态密码登录 和 找回密码预加载
	 *
	 * @author snailzhang
	 * @date 2017年7月20日
	 *
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "prePhone", method = RequestMethod.POST)
	@ResponseBody 
	public CS prePhone(HttpSession session) {
		log.info("================加载动态登录prePhone============");
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		CS cs = webClient.prePhone();
		return cs;
	}
	
	
	
	
	/**
	 * 手机登录、找回密码、动态登录
	 *
	 * @author snailzhang
	 * @date 2017年7月20日
	 *
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "phone", method = RequestMethod.GET)
	public String phone() {
		return "csair/mobileQueryOrder2";
	}
	
	/**
	 * 执行手机查询订单
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "phone", method = RequestMethod.POST)
	@ResponseBody
	public CsairReturnValue phone(HttpSession session,HttpServletRequest request) {
		log.info("==============执行手机查询（动态登录）=================");
		String username=request.getParameter("username");
		String vcodeReg=request.getParameter("vcodeReg");
//		log.info("手机:["+username+"]\n验证码:["+vcodeReg+"]");
		Csair webClient=(CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		CsairReturnValue returnValue = webClient.phone(username, vcodeReg);
			if (returnValue.getState()==CS.SUCCESS) {
				session.setAttribute(Csair.USERNAME, returnValue.getUserName());
				session.setAttribute(Csair.USERTYPE, returnValue.getUserType());
				session.setAttribute(Csair.IDENTIFYSTATUS, returnValue.getIdentifyStatus());
			}
		return returnValue;
	}
	
	/**
	 * 手机号查询订单发送验证码
	 * @param username
	 * @return
	 */
	@RequestMapping(value = "phoneYzm", method = RequestMethod.POST)
	@ResponseBody
	public CsairReturnValue registerYzm(HttpServletRequest request,HttpSession session)  {
		log.info("===============手机查询发送验证码================");
		String username=request.getParameter("username");
//		log.info("username------->"+username);
		Csair webClient=(CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		CsairReturnValue returnValue = webClient.phoneQueryVerifCode(username);
		return returnValue;
	}
}